<template>
  <div class="box">
    <div class="base">基本信息</div>
    <div>
      <div class="title">店铺名称</div>
      <div>
        <u-input disabled v-model="storeData.storeName" :custom-style="inputStyle"> </u-input>
      </div>
    </div>
    <div>
      <div class="title">店铺地址</div>
      <div>
        <u-input v-model="storeData.storeAddressPath" :custom-style="inputStyle"> </u-input>
      </div>
    </div>
    <div>
      <div class="title">详细地址</div>
      <div>
        <u-input v-model="storeData.storeAddressDetail" :custom-style="inputStyle"> </u-input>
      </div>
    </div>

    <div>
      <div class="title">店铺LOGO</div>
      <div>
        <u-upload :file-list="fileList" :header=" { accessToken: storage.getAccessToken() }" :action="action" width="200" @on-uploaded="onUploaded" :max-count="1" :show-progress="false"></u-upload>
      </div>
    </div>

    <div class="submit" @click="submit">保存/修改</div>

  </div>
</template>

<script>
import storage from "@/utils/storage.js";
import { saveShopInfo } from "@/api/shops";
import { upload } from "@/api/common.js";
export default {
  data() {
    return {
      storage,
      action: upload, //图片上传数据
      inputStyle: {
        background: "#f7f7f7",
        "padding-left": "20rpx",
        "border-radius": "10rpx",
      },
      storeData: {},
      fileList: [{ url: "" }],
    };
  },
  onLoad(options) {
    this.routerVal = JSON.parse(decodeURIComponent(options.data));
    this.storeData = this.routerVal;
    this.fileList[0].url = this.routerVal.storeLogo;
    this.storeData.address = this.routerVal.storeAddressPath;
    this.storeData.center = this.routerVal.storeCenter;
  },

  mounted() {},
  methods: {
    // 图片上传
    onUploaded(lists) {
      let images = [];
      lists.forEach((item) => {
        images.push(item.response.result);
      });
      this.fileList[0].url = images;
    },
    async submit() {
      this.storeData.storeLogo = this.fileList[0].url;
      let res = await saveShopInfo(this.storeData);
      if (res.data.success) {
        uni.showToast({
          title: "操作成功!",
          duration: 2000,
          icon: "none",
        });

        setTimeout(() => {
          uni.navigateBack({
            delta: 1,
          });
        }, 500);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.box {
  padding: 32rpx;
}
.title {
  font-weight: bold;
  margin: 40rpx 0;
}
.base {
  font-size: 38rpx;
  text-align: center;
}
</style>